const express = require('express')
const app = express()
const cors = require('cors')

// app.use(cors())
const whitelist = ['http://127.0.0.1:5500']
const corsOptions = {
    origin: function (origin, callback) {
        if (whitelist.indexOf(origin) != -1) {
            callback(null, true)
        } else {
            callback(new Error('Not allowed by CORS'))
        }
    }
}
app.use(cors(corsOptions))
app.get('/', (req, res) => {

    res.send('跨域')
})

app.listen(8000, () => { console.log('8000开启成功'); })